package hu.szyrt.bug.views;

import hu.szyrt.bug.R;
import hu.szyrt.bug.utils.Utils;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.view.View;
import android.view.View.OnFocusChangeListener;

public class SearchEditText extends EditText implements OnFocusChangeListener {

	public SearchEditText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	public SearchEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public SearchEditText(Context context) {
		super(context);
		init();
	}

	private void init(){
		this.setOnFocusChangeListener(this);
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		RelativeLayout.LayoutParams currentParams;
		if(hasFocus){
			currentParams = (RelativeLayout.LayoutParams) this.getLayoutParams();
			currentParams.width = getResources().getDimensionPixelSize(R.dimen.editSearchOpenWidth);
			this.setLayoutParams(currentParams);
		}else{
			if(this.getText().length() == 0){
				currentParams = (RelativeLayout.LayoutParams) this.getLayoutParams();
				currentParams.width = getResources().getDimensionPixelSize(R.dimen.editSearchDefaultWidth);
				this.setLayoutParams(currentParams);
			}
			Utils.hideKeyboard(v);
		}	
	}
	
}
